package com.woniu113.junk.order.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniu113.junk.order.dto.AllOrderLogDTO;
import com.woniu113.junk.order.model.OrderLog;
import com.woniu113.junk.order.mapper.OrderLogMapper;
import com.woniu113.junk.order.param.AllOrderLogParam;
import com.woniu113.junk.order.service.OrderLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu113.junk.order.util.Data;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 蜡笔没了小新
 * @since 2024年10月16日
 */
@Service
public class OrderLogServiceImpl extends ServiceImpl<OrderLogMapper, OrderLog> implements OrderLogService {

    @Resource
    private OrderLogMapper orderLogMapper;

    @Override
    public AllOrderLogDTO findAll(AllOrderLogParam param, Integer offset) {
        QueryWrapper<OrderLog> queryWrapper = new QueryWrapper<>();
        if (param.getUserType() != null && !param.getUserType().equals("")){
            queryWrapper.eq("user_type",param.getUserType());
        }
        int size = Math.toIntExact(orderLogMapper.selectCount(queryWrapper));
        queryWrapper.last("LIMIT " + offset + ", " + param.getPageSize());
        List<OrderLog> infos = orderLogMapper.selectList(queryWrapper);
        AllOrderLogDTO dto = new AllOrderLogDTO();
        dto.setList(infos);
        dto.setTotal(size);
        return dto;
    }
}
